package com.djf.eg.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.djf.eg.entity.SysRole;
import com.djf.eg.result.Result;
import com.djf.eg.service.RoleService;
import com.djf.eg.vo.RoleVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/roles")
public class RoleController extends DBaseController{
	@Autowired
	RoleService roleService;
	
	@GetMapping("")
	public Result getRoles(@RequestParam int pageNum, @RequestParam int pageSize) {
		Page<SysRole> roles = roleService.getRoles(pageNum, pageSize);
		return Result.success(new PageInfo<SysRole>(roles));
	}
//	@GetMapping("")
//	public Result getRoles() {
//		List<RoleVo> roles = roleService.getRoles();
//		return Result.success(roles);
//	}
	
	@GetMapping("/all")
	public Result getAllRoles() {
		List<RoleVo> roles = roleService.getRoles();
		return Result.success(roles);
	}
	
	@PostMapping("")
	public Result addRole(@RequestBody SysRole role) {
		roleService.addRole(role);
		return Result.success(role);
	}
	
	@PutMapping("")
	public Result updateRole(@RequestBody SysRole role) {
		SysRole result = roleService.updateRole(role);
		return Result.success(result);
	}
	
	@DeleteMapping("/{roleId}")
	public Result deleteRole(@PathVariable("roleId") Integer roleId) {
		roleService.deleteRole(roleId);
		return Result.success();
	}
}
